const Mock = require('mockjs')

const Random = Mock.Random

let Result = {
    code: 200,
    msg: '操作成功',
    data: null
}

// 验证码
Mock.mock('/captcha', 'get', ()=>{
    Result.data = {
        token: Random.string(32),
        captchaImg: Random.dataImage('100x40', 'p7n5w')
    }
    return Result
})

// 用户登录
Mock.mock('/login', 'post', ()=>{
    // 无法在header中传入jwt
    Result.msg = '登录成功'

    return Result
})

// 获取用户信息
Mock.mock('/sys/userInfo', 'get', ()=>{
    Result.data = {
        id: '1',
        username: 'test',
        avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
    }
    return Result
})

// 退出登录
Mock.mock('/logout', 'post', ()=>{
    Result.msg = '退出登录'
    return Result
})

// 路由请求
Mock.mock('/sys/menu/nav', 'get', ()=>{
    // 需要重新生成完整结构的导航菜单,侧边栏的显示也要重新写
    let nav = [
        {
            title: '系统管理',
            name: 'SysManage',
            icon: 'el-icon-s-operation',
            component: 'Home',
            path: '',
            children: [
                {
                    title: '用户管理',
                    name: 'UserManage',
                    icon: 'el-icon-user-solid',
                    path: '/sys/users',
                    component: 'sys/Users'
                },
                {
                    title: '角色管理',
                    name: 'RoleManage',
                    icon: 'el-icon-rank',
                    path: '/sys/roles',
                    component: 'sys/Roles',
                },
                {
                    title: '菜单管理',
                    name: 'MenuManage',
                    icon: 'el-icon-menu',
                    path: '/sys/menus',
                    component: 'sys/Menus',
                }
            ]
        },
        {
            title: '系统工具',
            name: 'SysTool',
            icon: 'el-icon-setting',
            path: '',
            component: 'Home',
            children: [
                {
                    title: '数据字典',
                    name: 'DataDic',
                    icon: 'el-icon-notebook-2',
                    path: '/sys/dic',
                    component: 'sys/Dic',
                }
            ]
        }
    ]
    let authorities = []

    Result.data = {
        nav: nav,
        authorities: authorities
    }

    return Result
})